<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>上传旅行讨论资料</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="/static/hAdmin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/hAdmin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/animate.css" rel="stylesheet">
    <link href="/static/hAdmin/css/style.css?v=4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="/static/hAdmin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <span id="gloUrl" style="display: none"></span>
      <h2> 发表我的旅行讨论</h2>
        <div class="ibox-content">
            <form class="form-horizontal m-t" id="commentForm">
                <span style="color: red">带星号的为必填项</span>
                <div class="form-group ">
                    <label class="col-sm-3 control-label"> <span style="color: red;font-size: 16px">*</span>讨论封面</label>
                    <div class="col-sm-8">
                    <input type="file" id="filePic" required="required" multiple="multiple" name="file"
                           class="form-control">
                    </div>
                </div>
                <div class="form-group ">
                    <label class="col-sm-3 control-label">文件附件</label>
                    <div class="col-sm-8">
                    <input type="file" id="file" required="required" multiple="multiple" name="file"
                           class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label"><span style="color: red;font-size: 16px">*</span>讨论标题：</label>
                    <div class="col-sm-8">
                        <input id="articleTitle"  minlength="2" type="text" class="form-control" required="" aria-required="true">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label"><span style="color: red;font-size: 16px">*</span>附件文件名：</label>
                    <div class="col-sm-8">
                        <input id="fileName"  minlength="2" type="text" class="form-control" required="" aria-required="true">
                    </div>
                </div>


                <div class="form-group">
                    <label class="col-sm-3 control-label"><span style="color: red;font-size: 16px">*</span>讨论分类：</label>
                    <div class="col-sm-8">
                        <select class="form-control" id="articleType">

                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">讨论内容：</label>
                    <div class="col-sm-8">
                        <textarea id="articleContent" rows="10" class="form-control"  ></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-3">
                        <button class="btn btn-primary" type="button" id="confirmAddArticle">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <!-- 全局js -->
    <script src="/static/hAdmin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/static/hAdmin/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="/static/hAdmin/js/content.js?v=1.0.0"></script>

    <!-- Sweet alert -->
    <script src="/static/hAdmin/js/plugins/sweetalert/sweetalert.min.js"></script>
    <!-- Peity -->
    <script src="/static/hAdmin/js/plugins/peity/jquery.peity.min.js"></script>

    <!-- Peity -->
    <script src="/static/hAdmin/js/demo/peity-demo.js"></script>
    <script src="/static/js/GloJs.js"></script>
    <!-- jQuery Validation plugin javascript-->
    <script src="/static/hAdmin/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="/static/hAdmin/js/plugins/validate/messages_zh.min.js"></script>
    <script src="/static/hAdmin/js/demo/form-validate-demo.js"></script>
    <script src="/static/hAdmin/js/plugins/toastr/toastr.min.js"></script>
    <script>

        $(function (){
            let Glo_BaseUrl = $("#gloUrl").attr("gloUValue")
            let Glo_user = localStorage.getItem("userId")
            //获取种类 标签
            function getTypeList(){
                $.ajax({
                    url: Glo_BaseUrl + "/tType/list",
                    type: "get",
                    data:{
                        "pageNum":1,
                        "pageSize":99
                    },

                    success: function (data) {
let str = ` <option value="">请选择讨论所属分类</option>
                          `
                        for (let i = 0; i < data.list.length; i++) {
                            let item = data.list[i]
                            str +=` <option value="${item.id}">${item.typeName}</option>`
                        }
$("#articleType").html("").append(str)
                    },
                    error: function () {
                        alert("服务器异常！network error！")
                    }
                })
            }
            getTypeList()
            //上传资料
            $("#confirmAddArticle").click(function () {

                if ($("#filePic")[0].files[0] == null || $("#filePic")[0].files[0] == undefined){
                    toastr.error("请上传封面", '提示')
                    return false;
                }
                if ($("#articleTitle").val() == null || $("#driverName").val() == ""){
                    toastr.error("请输入讨论标题", '提示')
                    return false;
                }



                var formData = new FormData();//这里需要实例化一个FormData来进行文件上传
                formData.append("file",$("#file")[0].files[0]);
                formData.append("title",$("#articleTitle").val());
                formData.append("fileName",$("#fileName").val());
                formData.append("content",$("#articleContent").val());
                formData.append("type",$("#articleType").val());
                formData.append("authorId",Glo_user);
                 formData.append("filePic",$("#filePic")[0].files[0]);
                formData.append("status","1");
                swal({
                    title: "提醒",
                    text: "您上传的讨论需要符合社区规范",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#38de4e",
                    confirmButtonText: "继续分享",
                    cancelButtonText:"我再想想",
                    closeOnConfirm: false
                }, function () {
                    $.ajax({
                        url: Glo_BaseUrl + "/tArticle/add",
                        type: "post",
                        data:formData,
                        processData : false,
                        contentType : false,
                        success: function (data) {
                            if (data.code === 200){
                                swal("发表成功！", "系统审核员将在后期进行审核，审核不通过的讨论将被强制下架。", "success");
                                toastr.info(data.msg, '即将自动跳转......')
                                setTimeout(function (){
                                    window.location.href = Glo_BaseUrl + "/web/pagesIndex"

                                },2000)
                            }else {
                                swal("上传失败！", data.msg, "error");
                                toastr.error(data.msg, '提示')
                            }

                            $(".forms input").val("")
                            $("#companyId").val("")
                        },
                        error: function () {
                            alert("服务器异常！network error！")
                        }
                    })

                });

            })

        })

    </script>

</body>

</html>
